const { formatResponse } = require("./tool")

// 自定义错误
class ServiceError extends Error{
    constructor(msg,code){
        super(msg);
        this.code = code
        this.msg = msg
    }

    toResponseJSON(){
        return formatResponse(this.code,this.msg,null)
    }
}

// 文件上传错误
exports.UploadError = class extends ServiceError{
    constructor(msg){
        super(msg,413);
    }
}

// 禁止访问
exports.ForbiddenError = class extends ServiceError{
    constructor(msg){
        super(msg,401);
    }
}

// 验证错误
exports.ValidationError = class extends ServiceError{
    constructor(msg){
        super(msg,406);
    }
}

//无资源错误
exports.NotFoundError = class extends ServiceError{
    constructor(){
        super("not fonud",404);
    }
}

// 未知错误
exports.UnknowError = class extends ServiceError{
    constructor(){
        super("server internal Error",500);
    }
}

module.exports.ServiceError = ServiceError